package com.ptszyxx.popose.module.base.login;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ActivityLoginCodeWorldBinding;
import com.ptszyxx.popose.module.base.login.vm.LoginCodeWorldVM;
import com.ysg.base.BaseActivity;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YStringUtil;

public class LoginCodeWorldActivity extends BaseActivity<ActivityLoginCodeWorldBinding, LoginCodeWorldVM> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_login_code_world;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public LoginCodeWorldVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(LoginCodeWorldVM.class);
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public void initViewObservable() {
        viewModel.uc.onSendCodeEvent.observe(this, o -> startTime());
        viewModel.uc.onLoginTypeEvent.observe(this, o -> setLoginTypeUI());
    }

    private void setLoginTypeUI() {
        if (YStringUtil.eq(2, viewModel.loginType)){
            binding.tvLoginType.setText("密码登录");
            binding.viewCode.setVisibility(View.VISIBLE);
            binding.viewPassword.setVisibility(View.GONE);
        }else{
            binding.tvLoginType.setText("验证码登录");
            binding.viewCode.setVisibility(View.GONE);
            binding.viewPassword.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 短信倒计时
     */
    private void startTime(){
        binding.tvSendCode.startTimeCountDown();
    }


}
